int sizeoftree(struct TreeNode* root)
{
    return root == NULL ? 0 : sizeoftree(root->left) + sizeoftree(root->right) + 1;
}
void preorder(struct TreeNode* root, int* a, int* pi)
{
    if (root == NULL)
        return;
    a[(*pi)++] = root->val;
    preorder(root->left, a, pi);
    preorder(root->right, a, pi);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize)
{
    int n = sizeoftree(root);
    int* a = (int*)malloc(sizeof(int) * n);
    int j = 0;
    preorder(root, a, &j);
    *returnSize = n;
    return a;
}